home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Bitmap / Sources / BmpFacet.cpp next >
Encoding:
Text File  |  1994-04-21  |  4.0 KB  |  152 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BmpFacet.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef BMPFACET_H
  14. #include "BmpFacet.h"
  15. #endif
  16.  
  17. #ifndef BMPFRAME_H
  18. #include "BmpFrame.h"
  19. #endif
  20.  
  21. #ifndef BMPPART_H
  22. #include "BmpPart.h"
  23. #endif
  24.  
  25. #ifndef BMPSEL_H
  26. #include "BmpSel.h"
  27. #endif
  28.  
  29. // ----- Framework Includes -----
  30.  
  31. #ifndef FWUTIL_H
  32. #include "FWUtil.h"
  33. #endif
  34.  
  35. // ----- Graphic Includes -----
  36.  
  37. #ifndef FWBMPSHP_H
  38. #include "FWBmpShp.h"
  39. #endif
  40.  
  41. // ----- Macintosh Includes -----
  42.  
  43. #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
  44. #include <ToolUtils.h>
  45. #endif
  46.  
  47. #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
  48. #include <math routines.h>
  49. #endif
  50.  
  51. #pragma segment bitmappart
  52.  
  53. //========================================================================================
  54. //    •• class CBitmapFacet
  55. //========================================================================================
  56.  
  57. //----------------------------------------------------------------------------------------
  58. //    • CBitmapFacet::CBitmapFacet
  59. //----------------------------------------------------------------------------------------
  60.  
  61. CBitmapFacet::CBitmapFacet()
  62. {
  63. }
  64.  
  65. //----------------------------------------------------------------------------------------
  66. //    • CBitmapFacet::~CBitmapFacet
  67. //----------------------------------------------------------------------------------------
  68.  
  69. CBitmapFacet::~CBitmapFacet()
  70. {
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. //    • CBitmapFacet::InitBitmapFacet
  75. //----------------------------------------------------------------------------------------
  76.  
  77. void CBitmapFacet::InitBitmapFacet(XMPFacet* xmpFacet, CBitmapPart *bitmapPart)
  78. {
  79.     this->InitFacet(xmpFacet);
  80.     fBitmapPart = bitmapPart;
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //    • CBitmapFacet::Draw
  85. //----------------------------------------------------------------------------------------
  86.  
  87. void CBitmapFacet::Draw(FW_CGraphicContext *gc)
  88. {
  89.     FW_CBitmapShape bitmap = fBitmapPart->GetBitmapShape();
  90.     
  91.     FW_CRect frameRect;
  92.     GetFrame()->GetFrameShapeBounds(&frameRect);
  93.     
  94.     // ----- Draw the bitmap -----
  95.     bitmap->SetRectangle(frameRect);
  96.     bitmap->Draw(gc);
  97.     
  98.     // ----- Draw the ants if there is a selection -----
  99.     if (GetFrame()->IsActive())
  100.     {
  101.         CBitmapSelection *bitmapSelection = fBitmapPart->GetBitmapSelection();
  102.         if (!bitmapSelection->IsEmpty())
  103.             bitmapSelection->DoDrawAnts(gc);
  104.     }
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    • CBitmapFacet::DoMouseDown
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_Boolean CBitmapFacet::DoMouseDown(const FW_CPoint& where, XMPEventData event)
  112. {    
  113.     FW_CPoint pt(where);
  114.     FW_CPoint zoomRatio = GetZoomRatio();
  115.     pt.x = ::FixDiv(pt.x, zoomRatio.x);
  116.     pt.y = ::FixDiv(pt.y, zoomRatio.y);
  117.     
  118.     CBitmapSelection *bitmapSelection = fBitmapPart->GetBitmapSelection();
  119.     
  120.     // ----- If clicked into the selection start a drag -----
  121.     if (bitmapSelection->InSelection(pt))
  122.     {
  123.         bitmapSelection->Drag(this, event);
  124.     }
  125.     else 
  126.     {
  127.         // ----- Otherwise close the selection... -----
  128.         {
  129.             FW_CGraphicContext gc(*this);
  130.             bitmapSelection->CloseSelection();
  131.         }
  132.         
  133.         // ----- ... and start a track -----
  134.         FW_CRect rect;
  135.         if (bitmapSelection->Track(this, where, event, rect))
  136.         {        
  137.             bitmapSelection->SetSelectRect(rect);
  138.             bitmapSelection->DrawAnts(GetFrame());
  139.         }
  140.     }
  141.     
  142.     return TRUE;
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    • CBitmapFacet::GetZoomRatio
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CPoint CBitmapFacet::GetZoomRatio() const
  150. {
  151.     return ((CBitmapFrame*)GetFrame())->GetZoomRatio();
  152. }